package com.qf.exam01.utils;

import java.util.Random;

public class IPUtils {
    /**
     * 产生一个随机的IP
     * @return
     */
    public static IP randomIP(){
        Random random = new Random();
        int partA = random.nextInt(256);
        int partB = random.nextInt(256);
        int partC = random.nextInt(256);
        int partD = random.nextInt(256);
        IP ip = new IP();
        ip.setPartA(partA);
        ip.setPartB(partB);
        ip.setPartC(partC);
        ip.setPartD(partD);
        return ip;
    }

    /**
     * 指定 partA的随机IP
     * @param partA
     * @return
     */
    public static IP randomIP(Integer partA){
        Random random = new Random();
        int partB = random.nextInt(256);
        int partC = random.nextInt(256);
        int partD = random.nextInt(256);
        IP ip = new IP();
        ip.setPartA(partA);
        ip.setPartB(partB);
        ip.setPartC(partC);
        ip.setPartD(partD);
        return ip;
    }

    /**
     * 指定 partA 和 partB
     * @param partA
     * @param partB
     * @return
     */
    public static IP randomIP(Integer partA,Integer partB){

        Random random = new Random();
        int partC = random.nextInt(256);
        int partD = random.nextInt(256);
        IP ip = new IP();
        ip.setPartA(partA);
        ip.setPartB(partB);
        ip.setPartC(partC);
        ip.setPartD(partD);
        return ip;
    }

    /**
     * 指定 partA ,partB,partC
     * @param partA
     * @param partB
     * @param partC
     * @return
     */
    public static IP randomIP(Integer partA,Integer partB,Integer partC){

        Random random = new Random();
        int partD = random.nextInt(256);
        IP ip = new IP();
        ip.setPartA(partA);
        ip.setPartB(partB);
        ip.setPartC(partC);
        ip.setPartD(partD);
        return ip;
    }

    public static void main(String[] args) {

        System.out.println(IPUtils.randomIP());
    }
}
